Jaccard

Implements the Jaccard index, also known as the Jaccard similarity coefficient (Jaccard, 1912).

Each input string is converted into a set of n-grams, the Jaccard index is then computed as \(\frac{\lVert V_1 \cap V_2 \rVert}{\lVert V_1 \cup V_2 \rVert}\). Like Q-Gram distance, the input strings \(X\) and \(Y\) are first converted into sets of n-grams \(V_1\) and \(V_2\) (sequences of n characters, also called k-shingles), but this time the cardinality of each n-gram is not taken into account.

The distance is computed as \(1 - similarity(X, Y)\).

References

Jaccard, P. (1912-02). The distribution of the flora in the alpine zone. New Phytologist, 11(2), 37–50. https://doi.org/10.1111/j.1469-8137.1912.tb05611.x[sci-hub]

Author

Thibault Debatty, solonovamax

See also

Constructors

Link copied to clipboard
constructor(k: Int = DEFAULT_K)

Properties

Link copied to clipboard
val k: Int

Functions

Link copied to clipboard
open override fun distance(s1: String, s2: String): Double

Computes the Jaccard distance of two strings.

fun distance(profile1: Map<String, Int>, profile2: Map<String, Int>): Double

Computes the Jaccard distance of precomputed profiles.

Link copied to clipboard
fun profile(string: String): Map<String, Int>

Compute and return the profile of s, as defined by Ukkonen (Ukkonen 1992). The profile is the number of occurrences of k-shingles, and is used to compute q-gram similarity, Jaccard index, etc. Pay attention: the memory requirement of the profile can be up to \(k \times \text{size of the string}\)

Link copied to clipboard
open override fun similarity(s1: String, s2: String): Double

Computes the Jaccard similarity of two strings.

fun similarity(profile1: Map<String, Int>, profile2: Map<String, Int>): Double

Computes the Jaccard similarity of precomputed profiles.